/*
 * Purchase.java 2012-8-21
 * Copyright(c) 20012-2015 by covidien
 * ALL Rights Reserved.
 */
package com.mvc.business.model;

import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;

import com.mvc.ProjectUtils;
import com.mvc.base.model.BaseCompany;
import com.mvc.base.model.Picture;
import com.mvc.base.model.Supplier;

/**
 * 
 * @author Bob pu [bangxiong.pu@covidien.com]
 * @version V1.0 Create Time: 2012-8-21
 */
@Entity(name = "B_PURCHASE")
public class Purchase extends BaseCompany {

	public static final int	   PURCHASE_TYPE_ORDER	= 1;
	public static final int	   PURCHASE_TYPE_OFFICE	= 2;

	public static final int	   STATUS_DRAFT	        = 1;
	public static final int	   STATUS_COMMIT	    = 10;
	public static final int	   STATUS_APPROVED	    = 20;
	public static final int	   STATUS_FINISHED	    = 50;

	public static final int	   FINANCE_STATUS_UNPAY	= 1;
	public static final int	   FINANCE_STATUS_PAYED	= 10;

	@NotNull
	private Integer	           orderId;
	@NotNull
	private Integer	           supplierId;
	@NotNull
	private Date	           purchaseDate;
	// 开单人
	@NotNull
	private Integer	           userId;
	@Length(max = 2048)
	private String	           remark;
	@Length(max = 256)
	private String	           payment;
	@NotNull
	private Date	           delivaryDate;
	@Length(max = 256)
	private String	           delivaryAddress;
	@Length(max = 2048)
	private String	           specification;
	@Length(max = 256)
	private String	           quality;
	@Length(max = 256)
	private String	           packing;
	@Length(max = 256)
	private String	           shipping;

	private Integer	           auditUserId;
	private Date	           auditDate;
	@NotNull
	private Integer	           status;
	@NotNull
	private Integer	           financeStatus;
	@NotNull
	private Integer	           type;
	@NotNull
	private Double	           total;
	@NotNull
	private Integer	           currency;

	// 预计付款日期
	private Date	           predictPayDate;
	private Date	           payDate;

	@Length(max = 64)
	private String	           backwardReason;

	@Transient
	private Order	           order;

	@Transient
	private Supplier	       supplier;

	@Transient
	private List<PurchaseItem>	purchaseItems;

	@Transient
	private List<Picture>	   pictures;

	/**
	 * @return the purchaseDate
	 */
	public Date getPurchaseDate() {
		return purchaseDate;
	}

	/**
	 * @return the order
	 */
	public Order getOrder() {
		return order;
	}

	/**
	 * @param order
	 *            the order to set
	 */
	public void setOrder(Order order) {
		this.order = order;
	}

	/**
	 * @param purchaseDate
	 *            the purchaseDate to set
	 */
	public void setPurchaseDate(Date purchaseDate) {
		this.purchaseDate = purchaseDate;
	}

	/**
	 * @return the purchaseNo
	 */
	public String getPurchaseNo() {
		return ProjectUtils.getPurchaseNo(getObjectId());
	}

	/**
	 * @return the remark
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * @param remark
	 *            the remark to set
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * @return the payment
	 */
	public String getPayment() {
		return payment;
	}

	/**
	 * @param payment
	 *            the payment to set
	 */
	public void setPayment(String payment) {
		this.payment = payment;
	}

	/**
	 * @return the delivaryDate
	 */
	public Date getDelivaryDate() {
		return delivaryDate;
	}

	/**
	 * @param delivaryDate
	 *            the delivaryDate to set
	 */
	public void setDelivaryDate(Date delivaryDate) {
		this.delivaryDate = delivaryDate;
	}

	/**
	 * @return the delivaryAddress
	 */
	public String getDelivaryAddress() {
		return delivaryAddress;
	}

	/**
	 * @param delivaryAddress
	 *            the delivaryAddress to set
	 */
	public void setDelivaryAddress(String delivaryAddress) {
		this.delivaryAddress = delivaryAddress;
	}

	/**
	 * @return the specification
	 */
	public String getSpecification() {
		return specification;
	}

	/**
	 * @param specification
	 *            the specification to set
	 */
	public void setSpecification(String specification) {
		this.specification = specification;
	}

	/**
	 * @return the quality
	 */
	public String getQuality() {
		return quality;
	}

	/**
	 * @param quality
	 *            the quality to set
	 */
	public void setQuality(String quality) {
		this.quality = quality;
	}

	public Integer getCurrency() {
		return currency;
	}

	public void setCurrency(Integer currency) {
		this.currency = currency;
	}

	/**
	 * @return the packing
	 */
	public String getPacking() {
		return packing;
	}

	/**
	 * @param packing
	 *            the packing to set
	 */
	public void setPacking(String packing) {
		this.packing = packing;
	}

	/**
	 * @return the shipping
	 */
	public String getShipping() {
		return shipping;
	}

	/**
	 * @param shipping
	 *            the shipping to set
	 */
	public void setShipping(String shipping) {
		this.shipping = shipping;
	}

	/**
	 * @return the auditUserId
	 */
	public Integer getAuditUserId() {
		return auditUserId;
	}

	/**
	 * @param auditUserId
	 *            the auditUserId to set
	 */
	public void setAuditUserId(Integer auditUserId) {
		this.auditUserId = auditUserId;
	}

	/**
	 * @return the status
	 */
	public Integer getStatus() {
		return status;
	}

	/**
	 * @param status
	 *            the status to set
	 */
	public void setStatus(Integer status) {
		this.status = status;
	}

	/**
	 * @return the financeStatus
	 */
	public Integer getFinanceStatus() {
		return financeStatus;
	}

	/**
	 * @param financeStatus
	 *            the financeStatus to set
	 */
	public void setFinanceStatus(Integer financeStatus) {
		this.financeStatus = financeStatus;
	}

	/**
	 * @return the orderId
	 */
	public Integer getOrderId() {
		return orderId;
	}

	/**
	 * @return the total
	 */
	public Double getTotal() {
		return total;
	}

	/**
	 * @param total
	 *            the total to set
	 */
	public void setTotal(Double total) {
		this.total = total;
	}

	/**
	 * @param orderId
	 *            the orderId to set
	 */
	public void setOrderId(Integer orderId) {
		this.orderId = orderId;
	}

	/**
	 * @return the type
	 */
	public Integer getType() {
		return type;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(Integer type) {
		this.type = type;
	}

	/**
	 * @return the supplierId
	 */
	public Integer getSupplierId() {
		return supplierId;
	}

	/**
	 * @param supplierId
	 *            the supplierId to set
	 */
	public void setSupplierId(Integer supplierId) {
		this.supplierId = supplierId;
	}

	/**
	 * @return the supplier
	 */
	public Supplier getSupplier() {
		return supplier;
	}

	/**
	 * @param supplier
	 *            the supplier to set
	 */
	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	/**
	 * @return the purchaseItems
	 */
	public List<PurchaseItem> getPurchaseItems() {
		return purchaseItems;
	}

	/**
	 * @param purchaseItems
	 *            the purchaseItems to set
	 */
	public void setPurchaseItems(List<PurchaseItem> purchaseItems) {
		this.purchaseItems = purchaseItems;
	}

	/**
	 * @return the userId
	 */
	public Integer getUserId() {
		return userId;
	}

	/**
	 * @param userId
	 *            the userId to set
	 */
	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Date getPredictPayDate() {
		return predictPayDate;
	}

	public void setPredictPayDate(Date predictPayDate) {
		this.predictPayDate = predictPayDate;
	}

	public Date getPayDate() {
		return payDate;
	}

	public void setPayDate(Date payDate) {
		this.payDate = payDate;
	}

	public List<Picture> getPictures() {
		return pictures;
	}

	public void setPictures(List<Picture> pictures) {
		this.pictures = pictures;
	}

	public String getOrderNo() {
		if (orderId != null) {
			return ProjectUtils.getOrderNo(orderId);
		}
		return "";
	}

	public String getBackwardReason() {
		return backwardReason;
	}

	public void setBackwardReason(String backwardReason) {
		this.backwardReason = backwardReason;
	}

	public Date getAuditDate() {
		return auditDate;
	}

	public void setAuditDate(Date auditDate) {
		this.auditDate = auditDate;
	}
}
